package sliver.action.shop;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import sliver.entity.Order;
import sliver.entity.Shopper;
import sliver.service.shop.order.OrderCRUDService;

import com.opensymphony.xwork2.ActionSupport;

@Scope("prototype")
@Controller("shop.toListOrderAction")
public class ToListOrderAction extends ActionSupport implements RequestAware, SessionAware{

	private static final long serialVersionUID = 962420097114067080L;
	
	private Map<String, Object> request;
	private Map<String, Object> session;
	
	@Autowired
	private OrderCRUDService orderCRUDService;
	
	public ToListOrderAction(){
		
	}

	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}
	
	@Override
	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}

	@Override
	public String execute() throws Exception {
		
		Shopper shopper = Shopper.class.cast(session.get("login_shopper"));
		List<Order> orders = orderCRUDService.showOrders(shopper.getId());
		request.put("orders", orders);
		
		return SUCCESS;
	}
}
